﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutNews.cshtml";
}

<link href="~/Common/News/news.css" rel="stylesheet" />

<div id="content">
    <h2 id="newTitle"></h2><br /><br />

    <ul id="newlist" class="list-group">

    </ul>
</div>

<script>
    $(function (){
        $.ajax({
            type: 'post',
            url: 'http://route.showapi.com/109-35',
            dataType: 'json',
            data: {
                "showapi_timestamp": formatterDateTime(),
                "showapi_appid": '91600', //这里需要改成自己的appid
                "showapi_sign": '788abfa1d9e04ec7b303634e00ab8b8f', //这里需要改成自己的应用的密钥secret
                "channelName": "国内焦点"
            },

            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert("操作失败!");
            },
            success: function (result) {
                for (var i in result.showapi_res_body.pagebean.contentlist) {

                    var news = $("<li><p class='title'>" + result.showapi_res_body.pagebean.contentlist[i].title + "</p><p class='date'>" + result.showapi_res_body.pagebean.contentlist[i].pubDate + "</p><a href=" + result.showapi_res_body.pagebean.contentlist[i].link + "><img src=" + result.showapi_res_body.pagebean.contentlist[i].imageurls[0].url + " /></a></li>");

                    $("ul.list-group").append(news);
                }
            }
        });

        ///////////////
        $(".find_nav_list ul li").click(function () {

            $("#newlist").empty();

                $("#newTitle").text($(this).text());
                var t = $(this).text();
                $.ajax({
                    type: 'post',
                    url: 'http://route.showapi.com/109-35',
                    dataType: 'json',
                    data: {
                        "showapi_timestamp": formatterDateTime(),
                        "showapi_appid": '91600', //这里需要改成自己的appid
                        "showapi_sign": '788abfa1d9e04ec7b303634e00ab8b8f', //这里需要改成自己的应用的密钥secret
                        "channelName": ""+t+""
                    },

                    error: function (XmlHttpRequest, textStatus, errorThrown) {
                        alert("操作失败!");
                    },
                    success: function (result) {
                        $("h2").text(t);
                        for (var i in result.showapi_res_body.pagebean.contentlist) {
                         
                            var news = $("<li><p class='title'>" + result.showapi_res_body.pagebean.contentlist[i].title + "</p><p class='date'>" + result.showapi_res_body.pagebean.contentlist[i].pubDate + "</p><a href=" + result.showapi_res_body.pagebean.contentlist[i].link + "><img src=" + result.showapi_res_body.pagebean.contentlist[i].imageurls[0].url + " /></a></li>");

                            $("ul.list-group").append(news);
                           
                        }
                    }
                });


            });

    });

    function formatterDateTime() {
        var date = new Date()
        var month = date.getMonth() + 1
        var datetime = date.getFullYear() +
            "" // "年"
            +
            (month >= 10 ? month : "0" + month) +
            "" // "月"
            +
            (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate()) +
            "" +
            (date.getHours() < 10 ? "0" + date.getHours() : date
                .getHours()) +
            "" +
            (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
                .getMinutes()) +
            "" +
            (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
                .getSeconds());
        return datetime;
    }
</script>

